package com.yuecai.modules.yc_order.service.factory;

import com.yuecai.modules.yc_order.service.OrderService;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class OrderFactory {

    private static Map<Integer, OrderService> map = new ConcurrentHashMap<Integer, OrderService>();

    public static void register(Integer type, OrderService ycOrderService){
        map.put(type,ycOrderService);
    }

    public static OrderService getOrderServiceByType(Integer type){
        if (type==null){
            throw new IllegalArgumentException("订单类型不能为空！");
        }
        OrderService ycOrderService = map.get(type);
        if (ycOrderService==null){
            throw new IllegalArgumentException("订单类型不存在！");
        }
        return ycOrderService;
    }
}
